## AC ##
T = int(input())
for i in range(T):
    x,y=tuple(int(el) for el in input().split(' '))
    if x==y:
        print( 1+x*(x-1) )
    elif x<y:
        base = 1+y*(y-1)
        if y%2:
            base += (y-x)
        else:
            base -= (y-x)
        print( base )
    else:
        base = 1+x*(x-1)
        if x%2:
            base -= (x-y)
        else:
            base += (x-y)
        print( base )
